package com.itheima.servlet03;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*1. 获取应用的参数
  2. 获取某个文件的硬盘路径(2个文件  src,web)
  3. 传递参数,让servletConfig案例的servlet进行打印()*/
@WebServlet("/studentServlet004")
public class studentServlet004 extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = getServletContext();
        System.out.println("context = " + context);

        String context01 = context.getInitParameter("Context01");
        System.out.println(context01);

        String realPath = context.getRealPath("/a.txt");
        System.out.println(realPath);

        String realPath1 = context.getRealPath("/WEB-INF/b.txt");
        System.out.println(realPath1);

        context.setAttribute("encoding", "uuuu");
        Object encoding = context.getAttribute("encoding");
        System.out.println("encoding = " + encoding);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
